<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="商品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productCode']" placeholder="请输入商品编码"></a-input>
        </a-form-item>
        <a-form-item label="商品名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productName']" placeholder="请输入商品名称"></a-input>
        </a-form-item>
        <a-form-item label="配送点" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['deliverSite']" placeholder="请输入配送点"></a-input>
        </a-form-item>
        <a-form-item label="英文名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['englishName']" placeholder="请输入英文名称"></a-input>
        </a-form-item>
        <a-form-item label="日文名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['japaneseName']" placeholder="请输入日文名称"></a-input>
        </a-form-item>
        <a-form-item label="客户商品编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['clientProductcode']" placeholder="请输入客户商品编码"></a-input>
        </a-form-item>
        <a-form-item label="商品规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productSize']" placeholder="请输入商品规格"></a-input>
        </a-form-item>
        <a-form-item label="产品属性" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productAttribute']" placeholder="请输入产品属性"></a-input>
        </a-form-item>
        <a-form-item label="存放温层" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['lodgeLayer']" placeholder="请输入存放温层"></a-input>
        </a-form-item>
        <a-form-item label="拆零控制" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['defuseControl']" placeholder="请输入拆零控制"></a-input>
        </a-form-item>
        <a-form-item label="码盘单层数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['plateSinglenum']" placeholder="请输入码盘单层数量"></a-input>
        </a-form-item>
        <a-form-item label="码盘层高" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['plateHeight']" placeholder="请输入码盘层高"></a-input>
        </a-form-item>
        <a-form-item label="计费商品类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['payType']" placeholder="请输入计费商品类"></a-input>
        </a-form-item>
        <a-form-item label="商品条码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productBarcode']" placeholder="请输入商品条码"></a-input>
        </a-form-item>
        <a-form-item label="商品品牌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['productBrand']" placeholder="请输入商品品牌"></a-input>
        </a-form-item>
        <a-form-item label="保质期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shelfLife']" placeholder="请输入保质期"></a-input>
        </a-form-item>
        <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['unit']" placeholder="请输入单位"></a-input>
        </a-form-item>
        <a-form-item label="拆零单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['defuseUnit']" placeholder="请输入拆零单位"></a-input>
        </a-form-item>
        <a-form-item label="体积" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bulk']" placeholder="请输入体积"></a-input>
        </a-form-item>
        <a-form-item label="重量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['weight']" placeholder="请输入重量"></a-input>
        </a-form-item>
        <a-form-item label="允收天数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['admitReceivedays']" placeholder="请输入允收天数"></a-input>
        </a-form-item>
        <a-form-item label="拆零数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['defuseNum']" placeholder="请输入拆零数量"></a-input>
        </a-form-item>
        <a-form-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['price']" placeholder="请输入价格"></a-input>
        </a-form-item>
        <a-form-item label="长" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['length']" placeholder="请输入长"></a-input>
        </a-form-item>
        <a-form-item label="宽" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wide']" placeholder="请输入宽"></a-input>
        </a-form-item>
        <a-form-item label="高" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['height']" placeholder="请输入高"></a-input>
        </a-form-item>
        <a-form-item label="单位组" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['unitGroup']" placeholder="请输入单位组"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'


  export default {
    name: "MesChiefdataProductModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/chiefdata/mesChiefdataProduct/add",
          edit: "/chiefdata/mesChiefdataProduct/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'productCode','productName','deliverSite','englishName','japaneseName','clientProductcode','productSize','productAttribute','lodgeLayer','defuseControl','plateSinglenum','plateHeight','payType','productBarcode','productBrand','shelfLife','unit','defuseUnit','bulk','weight','admitReceivedays','defuseNum','price','length','wide','height','unitGroup'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'productCode','productName','deliverSite','englishName','japaneseName','clientProductcode','productSize','productAttribute','lodgeLayer','defuseControl','plateSinglenum','plateHeight','payType','productBarcode','productBrand','shelfLife','unit','defuseUnit','bulk','weight','admitReceivedays','defuseNum','price','length','wide','height','unitGroup'))
      },

      
    }
  }
</script>